package com.joven.shelltest.utils.initStrategy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Author: wzj
 * @Date: 2024/3/4 11:12
 */
@Slf4j
@Component
public class DealStrategyFactory implements InitializingBean {
    private Map<String, DealCommonService> needsMap;

    @Autowired(required = false)
    private List<DealCommonService> needsHandler;

    @Override
    public void afterPropertiesSet() throws Exception {
        if (needsHandler != null) {
            needsMap = new HashMap<>(16);
            for (DealCommonService doService : needsHandler) {
                needsMap.put(doService.getType(), doService);
            }
        }
    }

    public void processing(String type, Map<String, Object> columns, Integer confId) {
        if (Objects.nonNull(needsMap.get(type))) {
            needsMap.get(type).processing(columns, confId);
        }
    }
}
